
package edu.indiana.application;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class UserInterface implements ActionListener{

        JFrame frame;
        JPanel panel;
        JButton conceptButton;
        JButton microTheoryButton;
        JComboBox microTheoryListBox;
        JTextField concept;
        JLabel conceptLabel;
        JLabel microTheoryLabel;
       
        public UserInterface() {
                GridLayout layout = new GridLayout(3,3);
                List<String> mtValues = new ArrayList<String>();
                //Todo: replace the below code to populate this list box
                mtValues.add("Test1");
                mtValues.add("Test2");
                mtValues.add("Test3");
               
                frame = new JFrame("Opencyc");
                panel = new JPanel();
                microTheoryButton = new JButton("Submit MT");
                microTheoryListBox = new JComboBox(mtValues.toArray());
                concept = new JTextField(10);
                conceptLabel = new JLabel("Enter the name of the concept:");
                conceptButton = new JButton("Submit Concept");
                microTheoryLabel = new JLabel("Select the miro theory:");
               
                frame.setLayout(layout);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.getContentPane().add(panel);
                panel.add(conceptLabel);
                panel.add(concept);
                panel.add(conceptButton);
                conceptButton.addActionListener(this);
                panel.add(microTheoryLabel);
                panel.add(microTheoryListBox);
                panel.add(microTheoryButton);
                microTheoryButton.addActionListener(this);
               
                frame.setSize(500, 500);
               
                frame.setVisible(true);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
                if(e.getSource().equals(microTheoryButton)){
                        //TODO: Need to get all genls for this and populate the text area
                        System.out.println(microTheoryListBox.getSelectedItem());
                        System.out.println("micro theory submit button presses");
                }else if(e.getSource().equals(conceptButton)){
                        System.out.println("Concept submit button presses");
                        //TODO: call a function which populates the list box with microtheory values
                        //for this particular concept
                        new Thread(new Runnable(){

                        @Override
                        public void run() {
                                // TODO Auto-generated method stub
                                cycTalk talkToCyc = new cycTalk();
                                talkToCyc.getGenls(concept.getText());
                        } }).start();
                       
                }
               
        }
}

